
proc
/*
These are a list of procs that do the spells, they take a simple mob as
an argument and can be used pretty easily
*/

	HealMinor (mob/M as mob)
		M.overlays+=/obj/overlay/heal
		M.Addhealth(M,rand(10,15))
		M << " Heal minor wounds was cast."
		spawn(30)
			if(M) M.overlays-=/obj/overlay/heal
	HealMedium (mob/M as mob)
		M.overlays+=/obj/overlay/heal
		M.Addhealth(M,rand(20,25))
		M << " Heal minor wounds was cast."
		spawn(30)
			if(M) M.overlays-=/obj/overlay/heal
	HealMajor (mob/M as mob)
		M.overlays+=/obj/overlay/heal
		M.Addhealth(M,rand(60,65))
		M << " Heal minor wounds was cast."
		spawn(30)
			if(M) M.overlays-=/obj/overlay/heal
	Neutralize(mob/pc/M as mob)
		M.overlays+=/obj/overlay/heal
		M.Poisoned = 0
		spawn(30)
			if(M) M.overlays-=/obj/overlay/heal
	PhaseDoor(mob/pc/M as mob)
		var/randx = rand(-5,10)
		var/randy = rand(-5,10)
		var/turf/T = locate(M.x+randx, M.y+randy, M.z)
		if (T.density)
			spawn PhaseDoor(M)
			return
		M.loc = T
	Teleport(mob/pc/M as mob)
		var/randx = rand(-10,10)
		var/randy = rand(-10,10)
		var/turf/T = locate(M.x+randx, M.y+randy, M.z)
		if (T.density)
			spawn Teleport(M)
			return
		M.loc = T
	RuneofReturn(mob/pc/M)
		M << "you feel the winds change around you"
		sleep(30)
		if (M.indungeon)
			if(M.gotoV2)
				//M.Teleport(locate(x,y,z))
			else
				M.Teleport(locate(36,14,1))
		else
			M.Teleport(locate(36,14,1))

/*
These procs are for using in game, much like the SD procs, which are Shadowdarkes
*/

	ishost(mob/person)
		if(!ismob(person) || !person.client)
			return 0
		else
			if(!person.client.address || person.client.address == world.address)
				return 1
			else
				return 0

	dancing_peeps()
		for(var/mob/npc/dancers/M)
			if(!M.notactive)
				M.notactive = 1
				M.Dancebyatch()


	ThingyList(list/list,and="and")
		if(list.len > 2)
			var/text
			var/i
			for(i = 1, i < list.len, i++)
				text += {"<a href ="http://www.byond.com/people/[list[i]]">[list[i]]</a>, "}
			text += {"[and] <a href ="http://www.byond.com/people/[list[list.len]]">[list[list.len]]</a>"}
			return text

		else if(list.len == 2)
			return {"<a href ="http://www.byond.com/people/[list[1]]">[list[1]]</a> [and] <a href ="http://www.byond.com/people/[list[2]]">[list[2]]</a>"}

		else if(list.len == 1)
			return {"<a href ="http://www.byond.com/people/[list[1]]">[list[1]]</a>"}

		else
			return null

	noHosting()
		if(world.port)
			for(var/mob/M in world)
				//world << "[M]"
				if(developers.Find(M.ckey))
					allowhosting = 1
					return
			if(!allowhosting)
				world << {"\red <font size = "5">You are not permitted to host the demo, you may restart by pressing return but hosting is not permitted.</font> - Maz"}
				del(world)
		spawn(50) noHosting()


//All this stuff is being phased out. It's left for reference purposes only
//Sets up the default variables and calls the login form
/*
	Login_Form()
		usr.savable = 0
		if(players_list.Find(usr))
			players_list -= usr
		usr.client.lazy_eye = 0
		usr.LStr = 50
		usr.LInt = 50
		usr.LCons = 50
		usr.LDex = 50
		usr.LAvail = 50
		usr.Gender = "male"
		var/Form/login_form/L = new()
		L.DisplayForm()

//Topic() code for game start
client/Topic(href,href_list[],hsrc)
	if(istype(usr, /mob/pc))
		if(length(href_list) > 25)
			world.log << "WARNING! [usr] may have just attempted to crash the server!"
			admin << "\red WARNING! [usr] may have just attempted to crash the server!"
			usr.Bad += 1
			if(length(href_list) > 50)
				usr.Bad +=1
			if(length(href_list) > 60)
				usr.Bad += 1
			if(usr.Bad >= 3)
				usr.savable = 0
				del(usr)
			return 0
		switch(href_list["action"])
			if("startgame")
				if(!usr.canNewLoad)
					usr.LStr = text2num(href_list["Str"])
					usr.LInt = text2num(href_list["Int"])
					usr.LCons = text2num(href_list["Con"])
					usr.LDex = text2num(href_list["Dex"])
					usr.LAvail = text2num(href_list["Ava"])
					var/LTotal = usr.LStr + usr.LInt + usr.LCons + usr.LDex + usr.LAvail
					if(LTotal > 250)
						usr << "<FONT color='red'>Hello [usr] T. Cheater! Welcome to Castle of the Winds Online!</FONT>"
						usr.LStr = 25
						usr.LInt = 25
						usr.LCons = 25
						usr.LDex = 25
						usr.LAvail = 150
						usr.cheater = 1
				else
					world << "<H1><FONT color='red'>WARNING!!! [usr] is attempting to CHEAT!!!!</FONT></H1>"

//Code to load the image for obj, mob, turf creation verbs
		if("loadpage")
			var/icon/Displayimage = new("[href_list["Iconfile"]]", "[href_list["Iconstate"]]")
			usr << browse_rsc(Displayimage,"displayimg.png")
			switch(href_list["Curpage"])
				if("createMonster")
					var/toBrowse = createMonster
					toBrowse += {"if (Main.MonsterType.options\[i].value == "[href_list["Monstertype"]]") {
Main.MonsterType.selectedIndex = \[i];
}
}
for (i=1;i<Iconlist.length - 1;i++) {
if (Main.MonsterState.options\[i].value == "[href_list["Iconstate"]]") {
Main.MonsterState.selectedIndex = \[i];
}
}
Main.MonsterName.value = "[href_list["Monstername"]]";
</SCRIPT></BODY></HTML>"}
					usr << browse(toBrowse)
				if("createObject")
					usr << browse(createObject)
				if("createTurf")
					var/toBrowse = layTurf
					toBrowse += {"if (Main.TurfType.options\[i].value == "[href_list["Turftype"]]") {
Main.TurfType.selectedIndex = \[i];
}
}
for (i=1;i<Iconlist.length - 1;i++) {
if (Main.TurfState.options\[i].value == "[href_list["Iconstate"]]") {
Main.TurfState.selectedIndex = \[i];
}
}
Main.TurfName.value = "[href_list["Turfname"]]";
</SCRIPT></CODE></BODY></HTML>"}
					usr << browse(toBrowse)

//Code for Admin createMonster
		if("createmonster")
			var/temp = href_list["Monstertype"]
			var/mob/monster/M = new temp(locate(usr.x,usr.y,usr.z))
			M.name = href_list["Monstername"]
			M.icon_state = href_list["Iconstate"]
			admin << "\red[usr] has created [M.name] the [temp] at [M.x], [M.y], [M.z]"
		if("createturf")
			var/temp = href_list["Turftype"]
			var/turf/template/T
			var/obj/O = new
			T = usr.loc
			O.underlays += T
			O.underlays += T.underlays
			O.overlays += T.overlays
			T = new temp(locate(usr.x,usr.y,usr.z))
			T.underlays+=O.underlays
			del(O)
			T.name = href_list["Turfname"]
			T.icon_state = href_list["Iconstate"]
			T.teleportx = text2num(href_list["Teleportx"])
			T.teleporty = text2num(href_list["Teleporty"])
			T.teleportz = text2num(href_list["Teleportz"])
			T.stext = href_list["Stext"]
			admin << "\red[usr] layed a [T.name]([temp]) at [T.x], [T.y], [T.z]"
	..()


*/
proc
	FindSpecialIcon(var/mob/pc/player as mob)

// This is a great proc dreamt up by Jon.
// It looks for anyone with a custom icon and gives them it.
// it depends on the gender mainly

		switch(player.Gender)

			if ("female")

				switch(player.ckey)
					if ("splattergnome")
						player.icon_state = "splatf"

					if ("maz")
						player.icon_state = "mazf"

					if("foomer")
						player.icon_state = "foomer_f"

					if("auzner")
						player.icon_state = "auzner_f"

					if("drakaden")
						player.icon_state = "drak_f"

					else
						player.icon_state = "f"

			if("male")

				switch(player.ckey)
					if ("nadrew")
						player.icon_state = "nadsm"

					if("jon88")
						player.icon_state = "jon"

					if("killerkirb")
						player.icon_state = "killerkirb"

					if("foomer")
						player.icon_state = "foomer_m"

					if("ebonshadow")
						player.icon_state = "ebonm"

					if("sapphiremagus")
						player.icon_state = "sapm"

					if("jigoku")
						player.icon_state = "jigoku"

					if("auzner")
						player.icon_state = "auzner_m"

					if("tatertots")
						player.icon_state = "tatertots"

					if("onefishdown")
						player.icon_state = "fisho"

					if("crashed")
						player.icon_state = "crashed"

					if("mortewarrior")
						player.icon_state = "mwarrior"

					if("gooddoggytreat")
						player.icon_state = "gdt"

					if("xooxer")
						player.icon_state = "xoox_m"

					if("shadowdarke")
						player.icon_state = "shadow"

					if("bery")
						player.icon_state = "lauren"

					if("mechadragon")
						player.icon_state = "mecha"

					if("drakaden")
						player.icon_state = "drak_m"

					if("maz")
						var/x = input(player,"[player.key], choose your iconstate","Rar") in list("m","mazm","maz2")
						player.icon_state = x

					else
						player.icon_state = "m"


//*********************************
//End Messed up proc area
//*********************************






//OBJECT PROCS

// basically this proc is to look in the contents of the object
// and to set the name and icon of the object that has the object
// inside to the object inside. It can be quite confusing.
// As of now I believe its legacy code as it isnt used.


//HUD OBJ PROC

// For making the text underneith the objects. I will probably be changing
// the font pretty soon to one that will fit twice in a tile.

obj/object
	proc/CreateName(r=0, g=r, b=r)
		overlays = list()
		var/lines = round(32 / namefont.height)
		var/txt = namefont.GetLines(name, width = 96, maxlines = lines,\
		                            flags = DF_WRAP_ELLIPSIS)
		var/size = namefont.RoundUp32(namefont.GetWidth(txt))
		var/iconset/s = namefont.DrawText(txt, size / 2, 0,\
		                    width = size, maxlines = lines,\
		                    flags = DF_JUSTIFY_CENTER | DF_WRAP_ELLIPSIS,\
		                    icons_x = size / 32, icons_y = 1)
		s.Transparent()     // white text on transparent background
		if(r<255 || g<255 || b<255)
			s.Blend(rgb(r, g, b), ICON_MULTIPLY)
		var/obj/O = new
		O.pixel_y = -32
		for(var/xx = 0, xx < s.w, ++xx)
			var/icon/ic = s.GetIcon(xx, 0)
			if(ic)
				O.icon = ic
				O.pixel_x = (xx + (1 - s.w) / 2) * 32
				overlays += O
		del(O)
	proc/RemoveName()
		for(var/v in overlays)
			overlays -= v


//TURF PROCS


//Other

proc

// Handy little proc that takes any text files and converts it into
// a scroll :)

	scroll_text(scroll_text,mob/M)
		M << browse({"<table border="0" cellspacing="0" width="450">
    <tr>
        <td background="http://maz.byond.com/Images/top.PNG" height = "65">
            &nbsp;
        </td>
    </tr>

    <tr>
        <td background="http://maz.byond.com/Images/side.PNG" height="900">
<TABLE WIDTH="80%" ALIGN="center"><TR><TD><center><b style="color: #0000ff; font-size: 2em;">Castle of the Winds Online</b>
<br>
<b>Created by team FourWinds</b>
<hr width=200>
<b style="color: #ff0000; font-size: 3em;">Commands</b>
<hr width=200>
Questions? Comments? Suggestions? Problems?<br>
Visit the <a href="http://games.byond.com/forums/Maz/CastleoftheWinds/index.cgi?action=forum_index">Forum</a> and share!
[scroll_text]
       </TD></TR></TABLE></td>

    <tr>
        <td background="http://maz.byond.com/Images/bottom.PNG" height = "65">
            &nbsp;
        </td>
    </tr>
</table>"})


// Xooxers anti-html proc taken from Chatters.


proc
	http_encode(var/text)
		var/pos1 = findtext(text,"http://")
		if(!pos1) pos1 = findtext(text, "byond://")
		if(!pos1) pos1 = findtext(text, "telnet://")
		if(!pos1) pos1 = findtext(text, "irc://")
		if(pos1)
			var/pos2
			var/part1
			var/link
			var/part2
			var/text_copy
			while(pos1)
				pos2 = findtext(text,"<",pos1)
				if(!pos2)
					pos2 = findtext(text," ",pos1)
				if(!pos2)
					pos2 = findtext(text,ascii2text(9),pos1)	// tab character
				if(!pos2)
					pos2 = findtext(text, ascii2text(10),pos1)	// newline character
				if(!pos2) pos2 = length(text)

				part1 = html_encode(copytext(text, 1, pos1))
				link = copytext(text, pos1, pos2)
				part2 = copytext(text, pos2)

				pos1 = findtext(part2, "http://")
				if(!pos1) pos1 = findtext(part2, "byond://")
				if(!pos1) pos1 = findtext(part2, "telnet://")
				if(!pos1) pos1 = findtext(part2, "irc://")
				text = part2

				if(!pos1)
					part2 = html_encode(part2)
					text_copy += part1 + link + part2
				else
					text_copy += part1 + link

			text = text_copy

		else
			text = html_encode(text)
		return text


// A proc that calls other procs (even from a variable)

	CallProc(ProcName as text, ProcSource, doCallArgs as num)
		if(ProcSource)
			if(doCallArgs)
				var/list/CallArgs = list()
				CallArgs = args.Copy(4)
				if(CallArgs)
					spawn() call(ProcSource, ProcName)(arglist(CallArgs))
					return
			spawn()call(ProcSource, ProcName)()
		else
			if(doCallArgs)
				var/list/CallArgs = list()
				CallArgs = args.Copy(4)
				if(CallArgs)
					spawn() call(ProcName)(arglist(CallArgs))
					return
			spawn()call(ProcName)()

	CallProc1(ProcName as text, ProcSource, arg1)
		if(ProcSource)
			call(ProcSource, ProcName)(arg1)
		else
			call(ProcName)(arg1)

	CallProc2(ProcName as text, ProcSource, arg1, arg2)
		if(ProcSource)
			call(ProcSource, ProcName)(arg1, arg2)
		else
			call(ProcName)(arg1, arg2)

	CallProc3(ProcName as text, ProcSource, arg1, arg2, arg3)
		if(ProcSource)
			call(ProcSource, ProcName)(arg1, arg2, arg3)
		else
			call(ProcName)(arg1, arg2, arg3)
